<?php
namespace app\school\model;
use think\Model;

class OrderModel extends Model
{
   
    public function getStatusAttr($value){
        if($value == 0){
            $str = '未处理';
        }else{
            $str = '已处理';
        }
        return $str;
    }
    public function getPayStatusAttr($value){
        if($value == 0){
            $str = '未支付';
        }elseif($value == 1){
            $str = '已支付';
        }elseif($value == 2){
            $str = '待确认退款';
        }elseif($value == 3){
            $str = '已退款';
        }
        return $str;
    }
    public function getPayTypeAttr($value){
        if($value == 1){
            $str = '现金';
        }elseif($value == 0){
            $str = '微信';
        }elseif($value == 2){
            $str = '扫码';
        }
        return $str;
    }
    public function getPayTimeAttr($value){
        if($value != 0){
            $time = substr($value,0,4) . '-' . substr($value,4,2) . '-' . substr($value,6,2) . ' ' . substr($value,8,2) . ':' . substr($value,10,2) . ':' . substr($value,12,2); 
        }else{
            $time = '';
        }
        return  $time;     
    }
    public function user(){
        return $this->belongsTo('UserModel','user_id');
    }    
    public function course(){
        return $this->belongsTo('SchoolCourseModel','course_id','id','b');
    }
    public function student(){
        return $this->belongsTo('UserStudentModel','student_id');
    }

    
    
    public function lists()
    {       
        $list = $this->order("id ASC")->paginate(10);
        return $list;
    }

    public function handle()
    {       
        $where = ['status' => 1];
        $list = $this->order("id ASC")->where($where)->paginate(10);
        return $list;
    }

    public function noHandle()
    {       
        $where = ['status' => 0];
        $list = $this->order("id ASC")->where($where)->paginate(10);
        return $list;
    }

    public function refund()
    {       
        $where = ['pay_status' => 3];
        $list = $this->order("id ASC")->where($where)->whereOr('pay_status',4)->paginate(10);
        return $list;
    }
}